<%--                                                                       --%>
<%-- Copyright (c) 2004-2005 BroadVision, Inc.  All rights reserved.       --%>
<%--                                                                       --%>
<%-- This software is copyrighted. Under the copyright laws, this software --%>
<%-- may not be copied, in whole or in part, without prior written consent --%>
<%-- of BroadVision, Inc. or its assignees. This software is provided      --%>
<%-- under the terms of a license between BroadVision and the recipient,   --%>
<%-- and its use is subject to the terms of that license.                  --%>
<%--                                                                       --%>
<%-- This software may be protected by one or more U.S. and International  --%>
<%-- patents.  Certain applications of BroadVision One-To-One software are --%>
<%-- covered by U.S. patent 5,710,887.                                     --%>
<%--                                                                       --%>
<%-- TRADEMARKS: BroadVision and BroadVision One-To-One are registered     --%>
<%-- trademarks of BroadVision, Inc., in the United States and the         --%>
<%-- European Community, and are trademarks of BroadVision, Inc., in other --%>
<%-- countries.  The BroadVision logo, is a trademark of BroadVision,      --%>
<%-- Inc., in the United States and other countries. Additionally, IONA    --%>
<%-- and Orbix are trademarks of IONA Technologies, Ltd.  RSA, MD5, and    --%>
<%-- RC2 are trademarks of RSA Data Security, Inc.                         --%>
<%--                                                                       --%>

<%@ page import="java.util.List" %>
<%@ page import="java.util.ListIterator" %>
<%@ page import="com.broadvision.process.tools.action.process.WorkStepGroup" %>
<%@ page import="com.broadvision.process.tools.action.process.WorkStep" %>

<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/struts-html-el.tld" prefix="html-el" %>
<%@ taglib uri="/WEB-INF/struts-bean-el.tld" prefix="bean-el" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>

<%
  String ctxPath = request.getContextPath();
%>

<script language="JavaScript">

function doNotificationAlert(currentTaskIn,currentTaskIndexIn,currentMinorTaskIn) {
   var thisForm = document.bpProcessInstanceSearchForm;
   thisForm.currentTask.value = currentTaskIn;     
   thisForm.currentTaskIndex.value = currentTaskIndexIn;     
   thisForm.currentMinorTask.value = currentMinorTaskIn; 
   thisForm.action = '<c:url value="/bp/processInstanceNotification.do"/>' ;
   thisForm.method = "post";
   thisForm.submit();   
   return false;                      
  }

</Script>

<jsp:useBean id="processInstanceTasksForm" 
          class="com.broadvision.process.tools.action.process.ProcessInstanceTasksForm"
          scope ="session"/>

<%
  java.util.HashMap map= new java.util.HashMap();
  map.put("instanceOid",request.getParameter("instanceOid"));
  pageContext.setAttribute("pagetabParam", map);
%>

<c:set var="viewAlertsImg">
<img src="<%= ctxPath %>/bp/images/action/icon_viewalerts.gif" width="15" height="15" border="0" class="actionIcon" alt="<bean-el:message key="bp.process.processInstanceTasks.icon.notification" bundle="bp.messages"/>" />
</c:set>
<c:set var="viewCollabImg">
<img src="<%= ctxPath %>/bp/images/action/icon_viewcollab.gif" width="15" height="15" border="0" class="actionIcon" alt="<bean-el:message key="bp.process.processInstanceTasks.icon.collaboration" bundle="bp.messages"/>" />
</c:set>
<c:set var="viewPolicyImg">
<img src="<%= ctxPath %>/bp/images/action/icon_viewpolicy.gif" width="15" height="15" border="0" class="actionIcon" alt="<bean-el:message key="bp.process.processInstanceTasks.icon.policy" bundle="bp.messages"/>" /></a>
</c:set>

<html-el:form action="/bp/processInstanceSearch.do">
<!--start zone 5 content area-->
<input type=hidden name="currentTask">
<input type=hidden name="currentTaskIndex">
<input type=hidden name="currentMinorTask">
    <table class="zoneFive" width="100%" border="0" cellspacing="0" cellpadding="0" summary="<bean-el:message key="bp.process.processInstance.contentArea" bundle="bp.messages"/>">
      <tr>
        <td valign="top" width="100%">
          <div class="pageTitle"><c:out value="${bpProcessInstanceForm.processInstance.customId}"/></div>
          <div><%@include file="/mc/common/pagetab.jsp" %></div>
          <div class="pageSubtitle">
            <span class="left"><bean-el:message key="bp.process.processInstanceTasks.header" bundle="bp.messages"/></span>
          </div> 

          <table class="dataTable" border="0" cellspacing="1" cellpadding="2" summary="<bean-el:message key="bp.process.processInstanceTasks.summary" bundle="bp.messages"/>" width="100%">

        <tbody>
            <tr>
<% 
                Object[] tasks = processInstanceTasksForm.getTasks();
                for (int i=0; i < tasks.length; i++) {
                 Object taskObj = tasks[i];
                 String taskName = null;
                 boolean activated = false;
                 WorkStep w = null;
                 if (taskObj instanceof WorkStep) {
                     w = (WorkStep)taskObj;
                     taskName = w.getTask();
                     activated = w.isActivated();
                 } else {
                     WorkStepGroup wsg = (WorkStepGroup) taskObj;
                     w = (WorkStep)wsg.getSteps().listIterator().next();
                     if (wsg.isSubStepsVisible()) {
                        //logical node

                        String firstTaskName =wsg.getFirstStepTask();
                        String lTaskName = wsg.getFirstStepLogicalTask();

                        if ( ( i % 2 ) == 0 ) { %>
                    <tr class="listEven"> 
              <% }else{ %>
              <tr class="listOdd">
              <% } %>
              
    <TD style="TEXT-INDENT: 0px" width="80%">
<a href="<%=response.encodeURL( ctxPath + "/bp/processInstanceTasks.do?instanceOid="+ processInstanceTasksForm.getInstanceOid() + "&toggleStep=" + i)%>">
<img src="<%= ctxPath %>/bp/images/icons/node_expand.gif" align=absMiddle border=0 title="<bean-el:message key="bp.process.processInstanceTasks.collapse" bundle="bp.messages"/>" alt="<bean-el:message key="bp.process.processInstanceTasks.collapse" bundle="bp.messages"/>" /></a>
<img title="<bean-el:message key="<%=\"bp.process.processInstanceTasks.tasktype.\"+w.getType()%>" bundle="bp.messages"/>" alt="<bean-el:message key="<%=\"bp.process.processInstanceTasks.tasktype.\" + w.getType() %>" bundle="bp.messages"/>" src="<%= ctxPath %>/bp/images/icons/<%= w.getType() %>.gif" align=absmiddle border=0>
<%= i > 0 && i <tasks.length-1 ? String.valueOf(i) + ": " : "&nbsp;&nbsp;&nbsp;&nbsp;" %><a href="<%= response.encodeURL( ctxPath + "/bp/processInstanceCollaboration.do?currentTask="+ firstTaskName)%>"><%= lTaskName %></a><%= wsg.isActivated() && !wsg.isSubStepsVisible()?"&nbsp;<img src=\"" + ctxPath +"/bp/images/icons/node_current.gif\"/>":""%></td><td>&nbsp;</td>
                <td noWrap headers="Actions">&nbsp;
                </td>
              </tr>

<%                    //sub steps
            for (ListIterator it = wsg.getSteps().listIterator(); it.hasNext();) {
              w = (WorkStep)it.next();
              taskName = w.getTask();
              activated = w.isActivated();
              pageContext.setAttribute("taskName", taskName);       
              if ( ( i % 2 ) == 0 ) { %>
                <tr class="listEven"> 
              <% } else { %>
                <tr class="listOdd">
              <% } %>

          <td style="TEXT-INDENT: 48px" width="70%"> 
            <img title="<bean-el:message key="<%=\"bp.process.processInstanceTasks.tasktype.\"+w.getType()%>" bundle="bp.messages"/>" alt="<bean-el:message key="<%=\"bp.process.processInstanceTasks.tasktype.\"+w.getType()%>" bundle="bp.messages"/>" src="<%= ctxPath %>/bp/images/icons/<%=w.getType()%>.gif" align=absmiddle border=0>
            <a href="<%=response.encodeURL( ctxPath + "/bp/processInstanceTaskDetail.do?currentTask="+ taskName)%>"><%= taskName %></a><%=activated?"&nbsp;<img src=\"" + ctxPath +"/bp/images/icons/node_current.gif\"/>":""%></td>
                <td noWrap width="10%"><bean-el:message key="<%=\"bp.process.task.state.\"+ w.getState() %>" bundle="bp.messages"/>
                </td>
                <td noWrap align=left width="20%">
 <% if (!"beginning".equals(w.getType()) && !"ending".equals(w.getType())) { %>
                  <a href="<%= response.encodeURL(ctxPath + "/bp/processInstanceNotification.do?currentTask="+ taskName+"&currentTaskIndex="+i)%>">
                    <img src="<%= ctxPath %>/bp/images/action/icon_viewalerts.gif" width="15" height="15" border="0" alt="<bean-el:message key="bp.process.processInstanceTasks.icon.notification" bundle="bp.messages"/>" /></a>
 <% } if ("collaboration".equals(w.getType())) { %>
                  <a href="<%=response.encodeURL( ctxPath + "/bp/processInstanceCollaboration.do?currentTask="+ taskName)%>">
                    <img src="<%= ctxPath %>/bp/images/action/icon_viewcollab.gif" width="15" height="15" border="0" alt="<bean-el:message key="bp.process.processInstanceTasks.icon.collaboration" bundle="bp.messages"/>" /></a>               
 <% } if ("policy".equals(w.getType())) { %>      
                  <a href="<%=response.encodeURL( ctxPath + "/bp/processInstancePolicy.do?currentTask="+ taskName)%>">
                    <img src="<%= ctxPath %>/bp/images/action/icon_viewpolicy.gif" width="15" height="15" border="0" alt="<bean-el:message key="bp.process.processInstanceTasks.icon.policy" bundle="bp.messages"/>" /></a>
 <% } %>
                  </td>
              </tr>

<%
                          } //loop end of subtask
                          continue;
                     
                     } else {    // not visible
                         List l = wsg.getSteps();
                         w = (WorkStep)l.iterator().next();
                         taskName = w.getTask();
                         activated = w.isActivated();
                     }
                 }
                 
                 if ( ( i % 2 ) == 0 ) { %>
                    <tr class="listEven"> 
              <% } else { %>
              <tr class="listOdd">
              <% } %>

    <%  if (!(taskObj instanceof WorkStep)) { %>
    <td style="TEXT-INDENT: 0px" width="80%">

<a href="<%= response.encodeURL( ctxPath + "/bp/processInstanceTasks.do?instanceOid="+ processInstanceTasksForm.getInstanceOid() + "&toggleStep=" +i)%>"><img src="<%= ctxPath %>/bp/images/icons/node_collapse.gif" align=absMiddle border=0 title="<bean-el:message key="bp.process.processInstanceTasks.expand" bundle="bp.messages"/>" alt="<bean-el:message key="bp.process.processInstanceTasks.expand" bundle="bp.messages"/>" /></a>
 <% } else { %>
 <td style="TEXT-INDENT: 19px" width="80%">
 <% } %>
 <img title="<bean-el:message key="<%=\"bp.process.processInstanceTasks.tasktype.\" + w.getType() %>" bundle="bp.messages"/>" alt="<bean-el:message key="<%=\"bp.process.processInstanceTasks.tasktype.\"+w.getType()%>" bundle="bp.messages"/>" src="<%= ctxPath %>/bp/images/icons/<%= w.getType() %>.gif" align=absmiddle border=0>
<% if (w.getState() >= 0) { %><%= i > 0 && i < tasks.length-1 ? String.valueOf(i) + ": ":"&nbsp;&nbsp;&nbsp;&nbsp;"%><a href="<%= w.getSubprocessUrl() %>"><%= w.getLogicalTask() %></a><%= activated ? "&nbsp;<img src=\"" + ctxPath +"/bp/images/icons/node_current.gif\"/>":""%></td>
    <td noWrap width="10%"><bean-el:message key="<%=\"bp.process.task.state.\"+ w.getState() %>" bundle="bp.messages"/>
    </td><td noWrap headers="Actions">
 <% if (!"beginning".equals(w.getType()) && !"ending".equals(w.getType())) { %>
                  <a href="<%= response.encodeURL( ctxPath + "/bp/processInstanceNotification.do?currentTask="+ taskName+"&currentTaskIndex="+i)%>"><c:out value='${viewAlertsImg}' escapeXml="false"/></a>
 <% } if ("collaboration".equals(w.getType())) { %>
                  <a href="<%= response.encodeURL( ctxPath + "/bp/processInstanceCollaboration.do?currentTask="+ taskName)%>"><c:out value='${viewCollabImg}' escapeXml="false"/></a>
 <% } if ("policy".equals(w.getType())) { %>      
                  <a href="<%= response.encodeURL( ctxPath + "/bp/processInstancePolicy.do?currentTask="+ taskName)%>"><c:out value='${viewPolicyImg}' escapeXml="false"/></a>
 <% } %>
                  </td>
<% } else  { %>
<%= i < tasks.length-1 && i > 0 ? String.valueOf(i) + ": " : "&nbsp;&nbsp;&nbsp;&nbsp;" %><%= w.getLogicalTask() %> </td><td noWrap width="10%"><bean-el:message key="<%=\"bp.process.task.state.\"+ w.getState() %>" bundle="bp.messages"/></td>
    <td noWrap headers="Actions">
 <% if (!"beginning".equals(w.getType()) && !"ending".equals(w.getType())) { %>
<!--                
<a href="<%=response.encodeURL( ctxPath + "/bp/processInstanceNotification.do?currentTask="+ taskName+"&currentTaskIndex="+i) + "&currentMinorTask=" + w.getLogicalTask()%>">
-->
<a href='javaScript:doNotificationAlert("<%= taskName %>","<%= i %>","<%= w.getLogicalTask() %>")'><c:out value='${viewAlertsImg}' escapeXml="false"/></a></td>
<% } } %>
              </tr>
           <% } // end of loop %>
          </table>
        </td>
      </tr>
    </table>

<!--end main content area here-->
<!--end zone 5 content area-->

</html-el:form>


